package ce.com.cenewbluesdk.entity.k3;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

/**
 * Created by Administrator on 2015/10/29 0029.
 */
public class Send_contacts implements Parcelable {

    private String  name;
    private String phoneNember;


    protected Send_contacts(Parcel in) {
        name = in.readString();
        phoneNember = in.readString();
    }

    public static final Creator<Send_contacts> CREATOR = new Creator<Send_contacts>() {
        @Override
        public Send_contacts createFromParcel(Parcel in) {
            return new Send_contacts(in);
        }

        @Override
        public Send_contacts[] newArray(int size) {
            return new Send_contacts[size];
        }
    };

    public String getName() {
        return name;
    }


    public byte[] getbyte(){
        byte [] b=new byte[40];
        byte[] nb=name.getBytes();
        byte[] pb=phoneNember.getBytes();
        if(pb.length>20){
            System.arraycopy(pb,0,b,0,20);
        }else{
            System.arraycopy(pb,0,b,0,pb.length);
        }

        if(nb.length>20){
            System.arraycopy(nb,0,b,20,20);
        }else{
            System.arraycopy(nb,0,b,20,nb.length);
        }

        return b;

    }

    public Send_contacts(byte [] bytes) {
        if(bytes==null||bytes.length!=40){
            this.name=null;
            this.phoneNember=null;
        }else{
            byte[] nb;
            byte[] pb;



            for(int i=1;i<=20;i++){
                if(i==20||(0 == bytes[i-1])){
                    if(i==20){
                        pb=new byte[i];
                        System.arraycopy(bytes,0,pb,0,i);
                    }else{
                        pb=new byte[i-1];
                        System.arraycopy(bytes,0,pb,0,i-1);
                    }

                    this.phoneNember=new String(pb);
                    Log.d("liu","phoneNember111="+phoneNember);
                    break ;
                }
            }
            for(int j=21;j<=40;j++){
                if(j==40||bytes[j-1]==0){

                    if(j==40){
                        nb=new byte[j-20];
                        System.arraycopy(bytes,20,nb,0,j-20);
                    }else{
                        nb=new byte[j-20-1];
                        System.arraycopy(bytes,20,nb,0,j-20-1);
                    }
                    this.name=new String(nb);
                    Log.d("liu","name  222  ="+name);
                    break;
                }
            }
        }



    }

    public Send_contacts() {
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhoneNember() {
        return phoneNember;
    }

    public void setPhoneNember(String phoneNember) {
        this.phoneNember = phoneNember;
    }

    public static int getItemSize() {
        return 40;
    }

    @Override
    public String toString() {
        return "Send_contacts{" +
                            "name='" + name + '\'' +
                            ", phoneNember='" + phoneNember + '\'' +
                            '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeString(phoneNember);
    }
}
